package com.internetplus.webcore.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.internetplus.webcore.entity.Business;
import com.internetplus.webcore.entity.Product;
import com.internetplus.webcore.mapper.BusinessMapper;
import com.internetplus.webcore.response.CodeMsg;
import com.internetplus.webcore.response.Result;
import com.internetplus.webcore.service.BusinessService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BusinessServiceImpl implements BusinessService {

    @Autowired
    private BusinessMapper businessMapper;

    @Override
    public Result getBusiness(int userId) {
        List<Business> list = businessMapper.getBusiness(userId);


        if(list.isEmpty()){
            return Result.error(CodeMsg.NOT_DATA_FOUND);
        }

        return Result.success(list);
    }

    @Override
    public Result updateBusiness(Business business) {
        businessMapper.updateBusiness(business);
        return Result.success(null);
    }

    @Override
    public Result getBusinessAll(int pageNum, int pageSize) {

        PageHelper.startPage(pageNum,pageSize);
        PageInfo pageInfo = new PageInfo(businessMapper.getBusinessAll());

        List<Business> list = pageInfo.getList();


        if (list.isEmpty()) {
            return Result.error(CodeMsg.NOT_DATA_FOUND);
        }

        return Result.success(pageInfo);
    }
}
